<%--
  Created by IntelliJ IDEA.
  User: 86157
  Date: 2021/12/30
  Time: 16:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>制定设计单</title>
</head>
<body>
<div>
    <div style="position: absolute; right: 10%">
        <input type="button" onclick="btnopen()" class="btn btn-info" value="添加工序">
        <input type="button" class="btn btn-info" value="删除工序" onclick="delgx()">
        <input type="button" class="btn btn-info" value="预览" onclick="previewsj()">
        <input type="button" class="btn btn-info" value="返回" id="fh">
    </div><br><br><br>
    <div class="container">
        <div style="position: absolute; left: 40%"><h4>生产工序设计单</h4></div><br><br><br>


        <input type="hidden" id="id" name="id">
        产品名称：<input type="text" name="productName" id="productName" readonly="readonly" style="border: none">
        产品编号：<input type="text" name="productId" id="productId" readonly="readonly" style="border: none">

        <div>设计人：<input type="text" style="border-left-style: none;border-right-style: none;border-top-style: none"></div>
        <%--表格展示数据--%>
        <table id="showData">

        </table>
        <div style="position: relative;top: -400px">
            <div>
                登记人：<input type="text" name="responsiblePerson"  id="responsiblePerson" style="border-left-style: none;border-right-style: none;border-top-style: none">
                登记时间：<input type="text" id="djDate" style="border: none"></div><br>
            <div>设计要求：<input type="text" style="width: 900px;height: 80px;"></div>
        </div>




        <!-- 模态框  选择物料  指向 childdemo页面-->
        <div id="openwin" class="modal">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body">
                    </div>
                </div>
            </div>
        </div>
</div>


    <script>
        var params={
            data:[],
            uniqueId:"procedureId",
            columns:[
                {
                    title: "全选",
                    field: "ck",
                    checkbox:true
                },
                {
                    title: "工序名称",
                    field: "procedureName"
                },
                {
                    title: "工序编号",
                    field: "procedureId"
                },
                {
                    title: "描述",
                    field: "procedureDescribe"
                },
                {
                    title: "工时数",
                    field: "labourHourAmount",
                    formatter: function (value, row, index) {
                        return "<input data-id='amount" + index + "'  type='text' class='form-control' value=''/>"
                    }
                },
                {
                    title: "工时单位",
                    field: "amountUnit",
                    formatter: function (value, row, index) {
                        return "<input data-id='amunit" + index + "'  type='text' class='form-control' value=''/>"
                    }
                },
                {
                    title: "单位工时成本",
                    field: "costPrice",
                    formatter: function (value, row, index) {
                        return "<input data-id='cprice" + index + "'  type='text' class='form-control' value=''/>"
                    }
                },
                {
                    title: "工时成本小计(元)",
                    field: "subtotal",
                    formatter: function (value, row, index) {
                        return "<span id='span" + index + "'></span>";
                    }
                }
            ]
        };
        $("#showData").bootstrapTable(params);

        var rows;
        //打开模态框
        /* $("#btnopen").click(function(){

             $("#openwin div[class='modal-body']").load("${pageContext.request.contextPath}/scgx/addgongxu.jsp");
            $("#openwin").modal("show");
        })*/
        function btnopen() {
            $.showDialogBoxByUrl("添加工序",
                "${pageContext.request.contextPath}/scgx/addgongxu.jsp",{},
                function (data) {
                    if (data==1){
                        rows=$("#addgongxu").bootstrapTable("getAllSelections");

                        $("#showData").bootstrapTable("load",rows);
                    }
                },"md")
        }

        //删除工序
        function delgx() {
            var rows2 = $("#showData").bootstrapTable("getAllSelections");
            for (var j =0;j<rows2.length;j++) {
                $("#showData").bootstrapTable("removeByUniqueId", rows2[j].procedureId);
            }
        }

        //登记时间
        var djtime= new Date();
        $("#djDate").val(djtime.toLocaleDateString()+'  '+djtime.toLocaleTimeString('chinese',{hour12:false}))

        $.get("${pageContext.request.contextPath}/dfilebyid.action",{id:${param.id}},function (data) {
            $("#productName").val(data.productName);
            $("#productId").val(data.productId);
            $("#responsiblePerson").val(data.responsiblePerson);
        }, "json")

        //工时成本小计
        $("#showData").on("change", function (e) {

            if (e.target.nodeName.toUpperCase() == "INPUT" && $(e.target).attr("type") == "text") {

                var str = $(e.target).attr("data-id");
                var index =parseInt( $(e.target).attr("data-id").substr(6));
                if(str.indexOf("amount")!=-1)
                {
                    var val = e.target.value;

                    var price = $(e.target).parent().next().next().find("input").val();

                    $("#span" + index).text(val * price);
                }
                else  if(str.indexOf("cprice") !=-1)
                {
                    var val = e.target.value;

                    var amount = $(e.target).parent().prev().prev().find("input").val();

                    $("#span" + index).text(val * amount);
                }


            }
        })


        //返回
        $("#fh").click( function () {
            location.href="${pageContext.request.contextPath}/scgx/mdesignProcedure.jsp";
        })

    </script>

</div>
</body>
</html>
